<?php

Raise::load('control.RaiseFormField');

/**
 * RaiseFormFieldCollection class
 * The need for putting more than one RaiseFormField into a single template in RaiseForm
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.UI.Form
 * @since 1.2
 */
class RaiseFormFieldCollection extends RaiseFormField {
    
    /**
     * A collection of RaiseFormField to be combined
     * @var RaiseTypedCollection
     */
    private $collection;

    function __construct() {
        $this->collection = new RaiseTypedCollection('RaiseFormField');
        $this->tag = new RaiseHtmlTag('div');
    }

    /**
     * Get the collection of RaiseFormField to be combined
     * @return RaiseTypedCollection
     */
    public function collection(){
        return $this->collection;
    }

    public function output() {
        $s = '';
        foreach($this->collection as $c){
            $s .= $c->output();
        }
        $this->tag->value($s);
        if($this->clientId()){
            $this->tag->attributes()->add('id', $this->clientId());
        }
        return $this->tag->html();
    }

}
